package log

import (
	"log"
	"os"
)

var(
	Info *log.Logger
	Debug *log.Logger
	Db *log.Logger
	Err *log.Logger
)

// 自己写的日志
func InitLog(dir string) {
	info, err := os.Stat(dir)
	if err != nil {
		err = os.MkdirAll(dir, 777)
		if err != nil {
			panic("无法访问或创建日志路径\r\n"+err.Error())
		}
	} else if !info.IsDir() {
		panic("日志路径被文件占用\r\n"+err.Error())
	}

	flag := log.Lmicroseconds | log.Llongfile | log.LstdFlags

	debugWriter := NewFileWriter(dir + "debug.log")
	Db = log.New(debugWriter, "DB:", flag)
	Debug = log.New(debugWriter, "DEBUG:", flag)

	Err = log.New(NewFileWriter(dir + "error.log"), "ERROR:", flag)
}